import { Application } from "egg";
import MQTTMachineToolsService from "./interface/tools";
import HCMQTTSystemService from "./interface/system";
import HCMQTTRecordService from "./interface/record";
import HCMQTTPersonService from "./interface/person";
import HCMQTTAudioService from "./interface/audio";
import HCMQTTParamsService from "./interface/params";

const symbolToolHQTTInstance = Symbol("#toolMQTTInstance")
const symbolSystemHQTTInstance = Symbol("#systemMQTTInstance")
const symbolRecordHQTTInstance = Symbol("#recordMQTTInstance")
const symbolPersonHQTTInstance = Symbol("#personMQTTInstance")
const symbolAudioHQTTInstance = Symbol("#audioMQTTInstance")
const symbolParamsHQTTInstance = Symbol("#paramsMQTTInstance")

export default class HCMQTTService {
    constructor(public topic: string, protected app: Application) {

    }

    get audio() {
        if (!this[symbolAudioHQTTInstance]) {
            this[symbolAudioHQTTInstance] = new HCMQTTAudioService(this.topic, this.app)
        }
        return this[symbolAudioHQTTInstance] as HCMQTTAudioService;
    }
    get params() {
        if (!this[symbolParamsHQTTInstance]) {
            this[symbolParamsHQTTInstance] = new HCMQTTParamsService(this.topic, this.app)
        }
        return this[symbolParamsHQTTInstance] as HCMQTTParamsService;
    }
    get person() {
        if (!this[symbolPersonHQTTInstance]) {
            this[symbolPersonHQTTInstance] = new HCMQTTPersonService(this.topic, this.app)
        }
        return this[symbolPersonHQTTInstance] as HCMQTTPersonService;
    }
    get record() {
        if (!this[symbolRecordHQTTInstance]) {
            this[symbolRecordHQTTInstance] = new HCMQTTRecordService(this.topic, this.app)
        }
        return this[symbolRecordHQTTInstance] as HCMQTTRecordService;
    }
    get system() {
        if (!this[symbolSystemHQTTInstance]) {
            this[symbolSystemHQTTInstance] = new HCMQTTSystemService(this.topic, this.app)
        }
        return this[symbolSystemHQTTInstance] as HCMQTTSystemService;
    }

    get tools() {
        if (!this[symbolToolHQTTInstance]) {
            this[symbolToolHQTTInstance] = new MQTTMachineToolsService(this.topic, this.app)
        }
        return this[symbolToolHQTTInstance] as MQTTMachineToolsService;
    }
}